﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace SCS
{
    static class Logger
    {
        static string FileName = "log.txt";

        static public void EraseLog()
        {
            if (File.Exists(FileName)) File.Delete(FileName);
        }

        static public void WriteMsg(string Text)
        {
            StreamWriter sw = new StreamWriter(FileName, true);
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + "=====================");
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + Text);
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + "=====================");
            sw.Flush();
            sw.Close();
        }

        static public void WriteLog(string Text)
        {
            StreamWriter sw = new StreamWriter(FileName, true);
            sw.WriteLine(DateTime.Now.ToLongTimeString()+ ": " + Text);
            sw.Flush();
            sw.Close();
        }

        static public void WriteError(string Text,string Source)

        {

            StreamWriter sw = new StreamWriter(FileName, true);
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + "****Exception********");
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + "LOCATION:" + Source);
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + "Description:" + Text);
            sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + "****End Exception****");
            sw.Flush();
            sw.Close();
        }

        
        static public void WriteErrorEvent(string Error, string Source)
        {
            System.Diagnostics.EventLog EV = new System.Diagnostics.EventLog();
            EV.Source = Source;
            EV.WriteEntry(Error, System.Diagnostics.EventLogEntryType.Error);
            EV.Close();

        }

        static public void WriteInfoEvent(string Error, string Source)
        {
            System.Diagnostics.EventLog EV = new System.Diagnostics.EventLog();
            EV.Source = Source;
            EV.WriteEntry(Error, System.Diagnostics.EventLogEntryType.Information);
            EV.Close();

        }

        static public void WriteWarningEvent(string Error, string Source)
        {
            System.Diagnostics.EventLog EV = new System.Diagnostics.EventLog();
            EV.Source = Source;
            EV.WriteEntry(Error, System.Diagnostics.EventLogEntryType.Warning);
            EV.Close();

        }

    
    
    }
}
